#pragma once
#include "IStream.h"

class StreamReaderBase : public IStreamReader {
public:
  StreamReaderBase(unsigned int caps);

  virtual IStream::streamsize_t Size() const;
  virtual IStream::streamoffs_t CurrentPos() const;
  virtual bool Seek(IStream::streamoffs_t offset, IStream::SeekType whence);

  virtual IStream::streamsize_t Read(IStream::streamsize_t size, char* dest);

protected:
  // Implementations: Call ResetStream when the stream changes. 
  // It sets the new size and resets the current position to 0.
  void ResetStream(IStream::streamsize_t newSize);
  
  // Implementations: implement DoSeek to set the new position
  // of the stream. The new position has already been error-checked,
  // so the only reason to return false would be catastrophic
  // failure.
  virtual bool DoSeek(IStream::streampos_t newPos) = 0;

  // Implementations: dest and size will be checked for errors
  // before DoRead() is called.
  virtual IStream::streamsize_t DoRead(IStream::streamsize_t size, char* dest) = 0;
private:
  IStream::streamsize_t size_;
  IStream::streampos_t pos_;
  unsigned int caps_;
};

